package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("设置店铺营业状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("前端传过来的营业状态是: {}",status == 1 ? "营业中":"打烊中");
        //1,把前端传过来的参数status营业状态舍之道redis中
        // key  value
        // SHOP_STATUS  status
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }

    @ApiOperation("管理端获取店铺营业状态")
    @GetMapping("/status")
    public Result getStatus(){
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        return Result.success(shopStatus);
    }
}
